package com.polaris.live.dialog

import android.content.Context
import android.view.View
import com.blankj.utilcode.util.ColorUtils
import com.blankj.utilcode.util.SpanUtils
import com.blankj.utilcode.util.StringUtils
import com.lxj.xpopup.core.CenterPopupView
import com.polaris.live.R
import com.polaris.live.common.constant.CommonConst
import com.polaris.live.common.ext.setOnSingleClickListener
import com.polaris.live.common.util.JsonUtils
import com.polaris.live.databinding.DialogSealAccountBinding
import com.polaris.live.resp.back_resp.SealAccountExt
import com.polaris.live.translation.R.*
import com.polaris.live.utils.route.RoutePath
import com.polaris.live.utils.route.Router
import com.polaris.live.utils.route.RouterUtils

/**
 * 封号账号登录弹窗
 *
 * @author Created by 长空 on 2023/11/02 09:51
 */
class SealAccountDialog(
    context: Context,
    private val content: String
) : CenterPopupView(context) {

    private lateinit var mBinding: DialogSealAccountBinding

    override fun getImplLayoutId(): Int {
        return R.layout.dialog_seal_account
    }

    override fun onCreate() {
        super.onCreate()
        mBinding = DialogSealAccountBinding.bind(popupImplView)

        val ext = JsonUtils.fromJson<SealAccountExt>(content)
        ext?.window?.let {
            if (it.appeal) {
                mBinding.tvAppeal.visibility = View.VISIBLE
                mBinding.tvAppeal.text = SpanUtils.with(mBinding.tvAppeal)
                    .append(StringUtils.getString(string.login_appeal))
                    .setUnderline()
                    .setForegroundColor(ColorUtils.getColor(R.color.loginAccountTextColor))
                    .create()
            } else {
                mBinding.tvAppeal.visibility = View.GONE
            }
            mBinding.tvAccountException.text = it.payload?.header
            if (it.payload?.highlight?.isNotEmpty() == true) {
                RouterUtils.handleText(
                    mBinding.tvContent, it.content,
                    it.payload.highlight
                )
            } else {
                mBinding.tvContent.text = it.content
            }
        }

        mBinding.tvAppeal.setOnSingleClickListener {
            Router.instance.setPath(RoutePath.ACCOUNT_APPEAL_ACTIVITY)
                .withLong(CommonConst.Login.LOGIN_USER_ID, ext?.window?.userId ?: 0L)
                .navigation()
        }

        mBinding.tvConfirm.setOnSingleClickListener {
            dismiss()
        }
    }
}